/** \file gr_containers.h Utility containers compatible with stl.
.*/
#pragma once

#include "gr_containers.h"
#include "gr_algorithms.h"
#include <boost/bimap.hpp>

namespace gr{


    class StringKeyGeneratorImpl
    {
        typedef boost::bimap<std::string, integer_key> bm_type;

        LinearKeyGenerator  internalGenerator_;
        LinearKeyGenerator& generator_;
        bm_type             map_;

        public:

        StringKeyGeneratorImpl():generator_(internalGenerator_)
        {}

        //StringKeyGeneratorImpl(LinearKeyGenerator& gen):generator_(gen){}

        integer_key getKey(const char* string)
        {
            integer_key result;
            if(hasKey(map_.left, string))
            {
                result = map_.left.at(std::string(string));
            }
            else
            {
                auto key = std::string(string);
                result = generator_();
                map_.insert(bm_type::value_type(key, result));
            }
            return result;
        }
    };

    StringKeyGenerator::StringKeyGenerator():map_(new StringKeyGeneratorImpl())
    {}
    //StringKeyGenerator::StringKeyGenerator(LinearKeyGenerator& gen):map_(new StringKeyGeneratorImpl(gen)){}
    StringKeyGenerator::~StringKeyGenerator(){delete map_;}
    integer_key StringKeyGenerator::getKey(const char* string)
    {
        return map_->getKey(string);
    }


}
